package com.example.netdisk.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

@Configuration
@ComponentScan("com.example.netdisk.controller")//扫描控制器组件，根据自己项目的controller实际路径填写
public class ViewResolverConfig implements WebMvcConfigurer {

    @Bean
    public ViewResolver viewResolver(){
        //将JSP文件放在WEB-INF文件夹下，从而避免JSP文件可以通过手动输入的URL被直接访问，只有控制器才能访问它们
        InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
        viewResolver.setPrefix("/WEB-INF/");
        viewResolver.setSuffix(".jsp");
        viewResolver.setViewNames("jsp/*");//当控制器返回的viewName符合规则时才使用这个视图解析器
        viewResolver.setOrder(2);//设置优先级,数值越小优先级越高
        return viewResolver;
    }


}


